﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace GrayParrot.Data.Obsolete
{
    [Obsolete]
    public class BackGroundWorkerWrapper<Result> : BackgroundWorker
    {
        private object m_callback;
        private object m_action;

        public BackGroundWorkerWrapper(Func<Result> action, BackgroundWorkerCallbackBase.Callback callback)
        {
            m_action = action;
            m_callback = callback;
        }

        protected override void OnDoWork(DoWorkEventArgs e)
        {
            base.OnDoWork(e);

            e.Result = ((Delegate)m_action).DynamicInvoke();
        }

        protected override void OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
        {
            base.OnRunWorkerCompleted(e);

            BackgroundWorkerCallbackBase.Callback callback = ((BackgroundWorkerCallbackBase.Callback)m_callback);

            callback(e.Result);
        }
    }
}
